// $Id$
// Licensed under Apache License Version 2.0
// See: http://www.apache.org/licenses/LICENSE-2.0.html
package de.servicezombie.tests.cxf;

import org.apache.cxf.message.Exchange;
import org.apache.cxf.message.ExchangeImpl;

import de.servicezombie.cxf.ServletApiAdapter;
import de.servicezombie.cxf.WebserviceTemplate;
import de.servicezombie.pub.r1.CommonRestResponse;

public class MockedWebserviceTemplate implements WebserviceTemplate {
	
	private static Exchange exchange = new ExchangeImpl();
	private static CommonRestResponse<?> webserviceResponse;
	
	public static void reset() {
		exchange = new ExchangeImpl();
		webserviceResponse = null;
	}
	
	@Override
	public Exchange getExchange() throws IllegalStateException {
		return exchange;
	}

	@SuppressWarnings("unchecked")
	@Override
	public <T> CommonRestResponse<T> getWebserviceResponse() {
		if(webserviceResponse == null) {
			webserviceResponse = new CommonRestResponse<T>();
		}
		
		return (CommonRestResponse<T>) webserviceResponse;
	}

	@Override
	public ServletApiAdapter getServletApiAdapter() {
		throw new UnsupportedOperationException("A ServletApiAdapter is not available in this implementation");
	}
}